<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-store"/>
    <meta http-equiv="Expires" content="0"/>
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/static/favicon2.ico}">
    <link rel="stylesheet" th:href="@{/static/plugins/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/static/css/layout.css}">
    <link rel="stylesheet" th:href="@{/static/css/common.css}">
    <style>
        .page-content {
            padding: 10px;
        }

        .layui-upload-img {
            width: 160px;
            height: 160px;
            /* margin: 0 10px 10px 0; */
            border: 1px solid #ddd;
            text-align: center;
            cursor: pointer;
        }

        a {
            color: cornflowerblue;
        }

        .must:after {
            content: "*";
            color: red;
        }

        a:hover {
            color: blue;
        }
    </style>
</head>
<body>
<div class="page-content">
    <form class="layui-form" id="form">
        <div class="layui-form-item">
            <label class="layui-form-label must">培训名称</label>
            <div class="layui-input-block">
                <input type="text" name="trainName" autocomplete="off" th:class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label must">培训时间</label>
            <div class="layui-input-block">
                <input type="text" id="trainDate" readonly="readonly" name="trainDate" autocomplete="off"
                       th:class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label must">培训机构</label>
            <div class="layui-input-block">
                <input type="text" name="trainOrganization" autocomplete="off" th:class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label must">培训成绩</label>
            <div class="layui-input-block">
                <input type="text" name="trainGrade" autocomplete="off" th:class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">培训证明</label>
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" src="/static/imgs/imgup.png" id="one">
                            <input type="hidden" name="certificateImg" class="certificateImg" id="uploadOneImg"
                                   lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-block">
                    <div class="layui-upload">
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" src="/static/imgs/imgup.png" id="two">
                            <input type="hidden" name="certificateImg" class="certificateImg" id="uploadTwoImg"
                                   lay-verify="required">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

</div>
<script th:src="@{/static/plugins/jquery.js}"></script>
<script th:src="@{/static/plugins/layui/layui.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/plugins/jquery-migrate-1.2.1.min.js}"></script>
<script th:src="@{/static/plugins/jquery.jqprint-0.3.js}"></script>
<script>
    //一般直接写在一个js文件中
    layui.use(['element', 'form', 'laydate', 'upload'], function () {
        var $ = layui.jquery
            , layer = layui.layer
            , upload = layui.upload,
            laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#trainDate' //指定元素
        });

        upload.render({
            elem: '#one'
            , url: '/storage/files/ul'
            , field: 'file'
            , accept: "images"
            , acceptMime: "image/jpg,image/jpeg,image/png"
            , size: 5120
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                var that = this;
                obj.preview(function (index, file, result) {
                    $(that.elem).attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code !== 200) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var $target = $(this.elem);
                $target.parent().find("#uploadOneImg").val(res.data.path);
            },
            error: function () {
                //演示失败状态
                var $target = $(this.elem);
                var demoText = $target.parent().find(".msg-box")
                demoText.html('<span style="color: #FF5722;">上传失败!</span>');
            }
        });
        upload.render({
            elem: '#two'
            , url: '/storage/files/ul'
            , field: 'file'
            , accept: "images"
            , acceptMime: "image/jpg,image/jpeg,image/png"
            , size: 5120
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                var that = this;
                obj.preview(function (index, file, result) {
                    $(that.elem).attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code !== 200) {
                    return layer.msg('上传失败');
                }
                //上传成功
                var $target = $(this.elem);
                $target.parent().find("#uploadTwoImg").val(res.data.path);
            },
            error: function () {
                //演示失败状态
                var $target = $(this.elem);
                var demoText = $target.parent().find(".msg-box")
                demoText.html('<span style="color: #FF5722;">上传失败!</span>');
            }
        });
    });
</script>
</body>

</html>